#coding=utf-8
#Boa:Frame:FrameSaleOrderShow

import wx

def create(parent):
    return FrameSaleOrderShow(parent)

[wxID_FRAMESALEORDERSHOW, wxID_FRAMESALEORDERSHOWNB, 
] = [wx.NewId() for _init_ctrls in range(2)]

class FrameSaleOrderShow(wx.Frame):

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAMESALEORDERSHOW,
              name=u'FrameSaleOrderShow', parent=prnt, pos=wx.Point(228, 77),
              size=wx.Size(1052, 693), style=wx.DEFAULT_FRAME_STYLE,
              title=u'\u9500\u552e\u67e5\u8be2')
        self.SetClientSize(wx.Size(1044, 659))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))
        self.Center(wx.BOTH)
        self.Bind(wx.EVT_CLOSE, self.OnFrameSaleOrderShowClose)

        self.nb = wx.Notebook(id=wxID_FRAMESALEORDERSHOWNB, name=u'nb',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(1044, 659),
              style=0)
        self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnNbNotebookPageChanged,
              id=wxID_FRAMESALEORDERSHOWNB)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.myInit()

    def myInit(self):
        import PanelSaleListTemp
        import PanelSaleList
        import PanelFund
        import PanelProduct
        import PanelDeliveryPlanList
        import PanelCustomerLogList
        
        # 令父窗口随子窗口一同出现
        import kit
        kit.conShow(self)
              
        # [self.iPageSaleTemp,self.iPagePlanList,self.iPageSaleList,self.iPageFund,
        # self.iPageDetail, self.iPageLog] = [i for i in range(6)] 
        [self.iPagePlanList,self.iPageSaleList,self.iPageFund,
        self.iPageDetail, self.iPageLog] = [i for i in range(5)] 
        
        # 销售订单、往来账务、销售明细 页面切换时共享客户
        self.pageShare = [self.iPageSaleList,self.iPageFund,self.iPageDetail, self.iPageLog]
        self.lastPeer = None
        
        # self.PanelSaleListTemp = PanelSaleListTemp.PanelSaleListTemp(self.nb)
        # self.nb.AddPage(imageId=-1, page=self.PanelSaleListTemp, select=True,
        #             text=u'订单草稿')

        self.panelPlanList = PanelDeliveryPlanList.PanelDeliveryPlanList(self.nb)
        self.nb.AddPage(imageId=-1, page=self.panelPlanList, select=False,
                    text=u'直送计划')
                                
        self.panelSaleList = PanelSaleList.PanelSaleList(self.nb, PanelSaleList.Type_Sale)
        self.nb.AddPage(imageId=-1, page=self.panelSaleList, select=False,
                    text=u'销售订单')
                  
        self.panelFund = PanelFund.PanelFund(self.nb, PanelFund.Type_Customer)
        self.nb.AddPage(imageId=-1, page=self.panelFund, select=False,
                    text=u'往来账务')
        
        self.panelDetail = PanelProduct.PanelProduct(self.nb, 
                                    PanelProduct.TypeSale, bSelect=False)
        
        self.nb.AddPage(imageId=-1, page=self.panelDetail, select=False,
                    text=u'销售明细')
        
        self.panelLog = PanelCustomerLogList.PanelCustomerLogList(self.nb, PanelCustomerLogList.Type_Sale)
        self.nb.AddPage(imageId=-1, page=self.panelLog, select=False,
                    text=u'客情日志')
    
    def showCustFund(self, peerObj):
        self.nb.SetSelection(self.iPageFund)
        self.panelFund.setSelectPeer(peerObj)
    
    def showCustLog(self, peerObj):
        self.nb.SetSelection(self.iPageLog)
        self.panelLog.setSelectPeer(peerObj)

    def showCustOrder(self, peerObj):
        self.nb.SetSelection(self.iPageSaleList)
        self.panelSaleList.setSelectPeer(peerObj)
        self.panelSaleList.OnBtnOneMonthButton(None)
        self.panelSaleList.OnBtnSearchButton(None)
        
    def OnNbNotebookPageChanged(self, event):
        oldPage = event.GetOldSelection()
        newPage = event.GetSelection()
        #if(oldPage != -1 and newPage != -1 and oldPage != self.iPageTemp and newPage != self.iPageTemp):
        print (oldPage, newPage, self.pageShare, self.lastPeer, )
        if (oldPage in self.pageShare):
            self.lastPeer = self.nb.GetPage(oldPage).getSelectPeer()
            
        if (self.lastPeer and newPage in self.pageShare):
            self.nb.GetPage(newPage).setSelectPeer(self.lastPeer)        
        event.Skip() # 必须保留这个，否则页面无法呈现

    def OnFrameSaleOrderShowClose(self, event):
        self.Show(False)
        #event.Skip()

    
    
